<?php

/**
 * AccessTokenModel 模型
 * Class AccessTokenModel
 */
class AccessTokenModel extends BaseModel
{

    public $tableName = "access_token";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'app_id'        => $data['app_id'],
                'access_token'  => $data['access_token'],
                'expires_time'  => $data['expires_time']
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }
}